package com.weilx959.spt.plugin.e2sp.component;

import com.weilx959.spt.core.utils.FXMLUtil;
import com.weilx959.spt.plugin.e2sp.constant.ExcelToSqlConstants;
import com.weilx959.spt.plugin.e2sp.controller.TableListCellController;
import com.weilx959.spt.plugin.e2sp.model.TransformedExcelVO;
import javafx.scene.control.ListCell;
import lombok.extern.slf4j.Slf4j;

/**
 * sheet列表单元格
 *
 * @author weilx
 * @since 2024-05-03
 */
@Slf4j
public class TableListCell extends ListCell<TransformedExcelVO.TableVO> {
    private final TableListCellController tableListCellController;

    public TableListCell() {
        tableListCellController = FXMLUtil.getController(this.getClass(), ExcelToSqlConstants.TABLE_LIST_CELL);
    }

    @Override
    protected void updateItem(TransformedExcelVO.TableVO table, boolean empty) {
        super.updateItem(table, empty);

        if (empty || table == null) {
            super.setText(null);
            super.setGraphic(null);
            super.setTooltip(null);
            return;
        }
        super.setText(null);
        super.setTooltip(null);
        tableListCellController.bind(table);
        super.setGraphic(tableListCellController.getSheetCellPane());
    }
}
